//简单事件处理
var event = {};

var eventList = [];
var eventFunc = [];

function listenEvent(eventName, fun) {
    if (eventList.indexOf(eventName) == -1) {
        eventList.push(eventName);

        eventFunc[eventName] = {
            name: eventName,
            funcs: []
        }

        eventFunc[eventName].funcs.push(fun);
    } else {
        eventFunc[eventName].funcs.push(fun);
    }
}

function fireEvent(eventName, extras) {
    if (eventList.indexOf(eventName) == -1) {
        eventList.push(eventName);

        eventFunc[eventName] = {
            name: eventName,
            funcs: []
        }
    } else {
        for (var i = 0; i < eventFunc[eventName].funcs.length; i++) {
            try {
                var fun = eventFunc[eventName].funcs[i];
                fun(extras);
            } catch (e) {
                console.log(e);
            }
        }
    }
}

event.listenEvent = listenEvent;
event.fireEvent = fireEvent;

module.exports = event;